package com.yanyeori.nacosa.controller;

import com.yanyeori.framework.core.model.WebResponse;
import com.yanyeori.nacosa.util.RestTemplateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chenkuan
 * @version v1.0
 * @desc 测试接口
 * @date 20/8/07 10:29
 */
@RestController
@RequestMapping("/testController")
public class TestController {

    @Autowired
    private RestTemplateUtil restTemplateUtil;

    private final String http = "http://";
    private final String nacosBServiceName = "nacos-b";

    @PostMapping("/rest")
    public WebResponse rest() {
        Map<String, Object> params = new HashMap<>();
        params.put("param", "nacos-a请求nacos-b的参数");
        WebResponse response = restTemplateUtil.postRequest(http + nacosBServiceName + "/testController/get", params, WebResponse.class);
        return response;
    }

    @PostMapping("/get")
    public WebResponse get(@RequestParam("param") String param) {
        return WebResponse.ok().data("a收到请求：" + param);
    }
}
